Skip to content

feat: add secret redaction feature to replace sensitive values#14

Merged
cre8ivejp merged 18 commits into
mainfrom
feat/redact-secrets
Jul 15, 2026
Merged

feat: add secret redaction feature to replace sensitive values#14
cre8ivejp merged 18 commits into
mainfrom
feat/redact-secrets

Conversation

@Ubisoft-potato

@Ubisoft-potato Ubisoft-potato commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

What

Redacts secret-looking values from the code lines sent to Bucketeer, replacing them with [REDACTED] so credentials near a flag reference don't leak into the dashboard or CSV output.

How

  • On by default (--redactSecrets, default true); disable with --redactSecrets=false or BUCKETEER_REDACT_SECRETS=false.
  • Detection is powered by the gitleaks ruleset (github.com/zricethezav/gitleaks/v8, MIT), covering hundreds of vendor credential formats with entropy checks.
  • A generic layer on top redacts Authorization header values, passwords in URLs (postgres://user:pass@host), and quoted or unquoted assignments to secret-keyword variables (apikey, secret, token, passwd, password, credential, auth). Unquoted values must be 12+ chars mixing letters and digits, so code like apiKey := opts.APIKey stays untouched; this also covers ~/.aws/credentials-style key pairs.
  • Detection runs on the whole hunk, so multi-line PEM private key blocks are fully redacted, including blocks cut off by the hunk boundary at either end.
  • Extensible via .bucketeer/coderefs.yaml: redactPatterns (extra regexes) and redactKeywords (extra variable-name keywords). Invalid patterns fail fast at startup.
  • Redaction happens at hunk creation, keeping the API payload, CSV output, and ContentHash consistent; flag matching runs on the original lines.

Also included

  • Fix: copy hunk lines so truncation doesn't mutate the file's cached lines.
  • CI: golangci-lint upgraded to v2.12.2; config migrated to v2 format.
  • go directive bumped to 1.25.0; vendor tree updated.

Example

awsKey := "AKIA..."                      // → awsKey := "[REDACTED]"
password := 'hunter2hunter2'             // → password := '[REDACTED]'
client.BoolVariation("someFlag", ...)    // → unchanged, flag still detected

Docs: Secret redaction.

@Ubisoft-potato
Ubisoft-potato marked this pull request as ready for review July 8, 2026 00:31
@Ubisoft-potato
Ubisoft-potato requested a review from cre8ivejp July 8, 2026 00:31
@cre8ivejp
cre8ivejp requested a review from Copilot July 8, 2026 00:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an opt-out-by-default secret redaction layer so code hunks sent to Bucketeer don’t leak credential-like values, while keeping flag matching based on the original (unredacted) source lines.

Changes:

  • Add a configurable redactor (built-in patterns + YAML extensibility) and apply it during hunk creation.
  • Wire redaction into matcher construction via a new --redactSecrets option (default true) plus YAML fields for extra patterns/keywords.
  • Update docs/tests and include .ldignore in ignore-file processing.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
search/search.go Copies hunk lines before mutation and applies optional redaction before truncation/hash generation.
search/search_test.go Updates expectations for hunks when context lines are disabled.
search/redact.go Implements the redaction engine and built-in credential patterns.
search/redact_test.go Adds unit/integration tests for redaction behavior and hunk redaction.
search/matcher.go Instantiates the redactor based on options and attaches it to Matcher.
search/files.go Adds .ldignore to the list of ignore files.
options/options.go Adds redaction-related options and validates user-provided regex patterns.
options/flags.go Introduces the --redactSecrets CLI flag (default true).
docs/CONFIGURATION.md Documents secret redaction configuration and YAML extensions.
README.md Adds a documentation link to the secret redaction section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread search/redact.go Outdated
@cre8ivejp

Copy link
Copy Markdown
Member

@Ubisoft-potato, it will be safer and more stable to use OSS, which is focused on scanning sensitive info.

Reference:
https://github.com/gitleaks/gitleaks
https://github.com/praetorian-inc/titus
https://github.com/trufflesecurity/trufflehog

While GitLeaks is more popular, Titus covers almost 3 times as much as GitLeaks, but it is still a bit new.
Either one would be better than implementing ourselves.
WDYT?

@cre8ivejp

Copy link
Copy Markdown
Member

This one is from the same author of GitLeaks. It's more accurate and faster.
https://github.com/betterleaks/betterleaks

Repository Gitleaks Betterleaks Speedup
Rails 24.5s 5.8s ✅ 4.2x faster
Ruby 55.2s 10.3s ✅ 5.4x faster
GitLab 11m28s 2m13s ✅ 5.2x faster

Is also developed in Go. We can try it!

@Ubisoft-potato
Ubisoft-potato force-pushed the feat/redact-secrets branch 3 times, most recently from 21c653b to dbf5485 Compare July 8, 2026 05:46
The previous golangci-lint v1.62.2 was built with Go 1.23 and fails on
the go 1.25.0 directive required by betterleaks. Migrate .golangci.yml
to the v2 config format (dead linters dropped by the migration tool),
keep gating parity by disabling linters introduced after v1.62 and
restricting staticcheck to SA checks, and fix the one new prealloc
finding.
Comment thread search/redact.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Comment thread search/redact.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Comment thread go.mod
Comment thread search/redact.go Outdated
Comment thread search/redact.go Outdated
The keyword-assignment regexes matched any [:=]+ run, so comparisons
like `if authType == "OAuth2.0"` or `token == expectedToken123` were
redacted. Spell the separator out as :=, =, or : and forbid a leading =
in unquoted values so the tail of == never matches.
godoc was split out of x/tools into its own module and frozen as
v0.1.0-deprecated. Inline its small IsText check instead.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 3 comments.

Comment thread options/options.go
Comment thread search/redact.go
Comment thread docs/CONFIGURATION.md Outdated
An empty (or empty-matching, e.g. "a*") pattern inserts [REDACTED]
between every character of every scanned line. Reject such patterns in
both options validation and newRedactor, and document the 6-character
floor for quoted keyword assignments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Comment thread search/search.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 6 comments.

Comment thread search/redact_test.go Outdated
Comment thread search/redact_test.go Outdated
Comment thread search/redact_test.go Outdated
Comment thread search/redact_test.go Outdated
Comment thread search/redact_test.go Outdated
Comment thread search/redact_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Comment thread search/matcher.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Comment thread search/search.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 1 comment.

Comment thread search/files.go

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 17 changed files in this pull request and generated 3 comments.

Comment thread search/redact_test.go
Comment thread search/redact_test.go
Comment thread search/redact_test.go

@cre8ivejp cre8ivejp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@cre8ivejp
cre8ivejp merged commit efa4995 into main Jul 15, 2026
3 checks passed
@cre8ivejp
cre8ivejp deleted the feat/redact-secrets branch July 15, 2026 07:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants